<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@ taglib prefix="s" uri="/struts-tags" %>
<%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>User Login in</title>
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link rel="stylesheet" href="css/default.css" type="text/css"></link>
  	<script type="text/javascript" src="js/jquery.js"></script>
  	<script type="text/javascript" src="js/jquery.form.js"></script>
  	<script type="text/javascript" src="js/common.js"></script>
  	<script type="text/javascript">
		$(function(){
		    var options={ 
		        beforeSubmit:validate,
		        success:showResponse
		    }; 
		    $('#myForm1').ajaxForm(options); 
		});
		
		
		var loginSubmitBtn=null;
		var loginErrorCount=0;//登录错误次数
		var num=0;
		var array=new Array(".  ",".. ","...");
		
		function validate(formData, jqForm, options) { 
			for (var i=0; i < formData.length; i++) {
		     	if(formData[i].name=="user.name"&&!formData[i].value){
		     		$("#loginMessage").text("请输入用户名");
		     		return false;
		     	}
		     	if(formData[i].name=="user.password"&&!formData[i].value){
		     		$("#loginMessage").text("请输入密码");
		     		return false;
		     	}
		    } 
		    var submitBut=$("input[name='submitBut']");
		    submitBut.attr("disabled","disabled");
		    submitBut.val("登录中...");
		    num=0;
		    loginSubmitBtn=setInterval(function dynamicValue(){
				submitBut.val("登录中"+array[num]);
				num++;
				num=num==3?0:num;
			},1000);
		    return true; 
		}
		
		function showResponse(responseText, statusText, xhr, $form)  { 
			var submitBut=$("input[name='submitBut']");
			var loginMessage=$("#loginMessage");
		    if(responseText==LOGIN.SUCCEED){
		    	clearInterval(loginSubmitBtn);
		    	loginSubmitBtn=null;
		    	submitBut.attr("disabled","disabled");
		    	loginMessage.text("");
			    submitBut.val("登录成功");
		    	alert("登录成功");
		    }else if(responseText==LOGIN.FAILURE){
		    	loginMessage.text("用户名或密码错误!");
		    	clearInterval(loginSubmitBtn);
		    	loginSubmitBtn=null;
			    submitBut.removeAttr("disabled");
			    submitBut.val("登录");
		    }else{
		    	alert("errorCode:"+responseText);
		    }
		} 
  	</script>
  </head>
  
  <body>
   	<form id="myForm1" action="account/loginIn" method="post" >
   	<table>
   		<tr><td colspan="2" align="center"><span style="font-size:24px;font-weight:bold;">登录</span></td></tr>
   		<tr><td colspan="2" align="center"><span id="loginMessage" style="color:red;"></span></td></tr>
	   	<tr><td align="right">用户名:</td><td><input type="text" maxlength="20" style="width:160px;" name="user.name" /></td></tr>
	   	<tr><td align="right">密&nbsp;&nbsp;&nbsp;&nbsp;码:</td><td><input type="password" maxlength="30" style="width:160px;" name="user.password" /></td></tr>
	   	<tr><td colspan="2" align="center"><input type="submit" name="submitBut" value="登录" /> <a href="account/register.html" >注册</a></td></tr>
	</table>
   	</form>
  </body>
</html>
